{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "969ea094",
   "metadata": {},
   "source": [
    "-----------------\n",
    "* 日期：2022-11-2\n",
    "* 课程：python\n",
    "* 记录人：Wuyue\n",
    "------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2387d4d",
   "metadata": {},
   "source": [
    "# 1.元组（tuple）\n",
    "> 1.元组的概念和基本形态   \n",
    "\n",
    "\n",
    "\n",
    "\n",
    "> 2.元组的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "78b0d441",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1800001, 1800002, 1800003) <class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "user_info = 1800001,1800002,1800003\n",
    "print(user_info,type(user_info))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5225ee85",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1800001, 1800002, 1800003] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "user_info_list = [1800001,1800002,1800003]\n",
    "print(user_info_list,type(user_info_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f1025774",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1800001\n",
      "(1800001, 1800002)\n"
     ]
    }
   ],
   "source": [
    "#取值\n",
    "print(user_info[0])\n",
    "#切片\n",
    "print(user_info[:2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "d625da69",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5328b560",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "time.struct_time(tm_year=2022, tm_mon=11, tm_mday=2, tm_hour=19, tm_min=11, tm_sec=50, tm_wday=2, tm_yday=306, tm_isdst=0)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.localtime()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "59f80724",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1667387621.750742"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "time.time() # 时间戳，可以记录互联网当中所有 数据信息产生、销毁、创建一系列行为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c9030b35",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.count(1800001)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "68476e36",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "user_info.index(1800001)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "64caa748",
   "metadata": {},
   "source": [
    "## 2. 集合\n",
    "> 1. 集合的概念和性质\n",
    ">> 1. 集合的唯一性\n",
    ">> 2. 集合无序性\n",
    "> 2. 集合的方法\n",
    ">> 1. 交集: 逻辑运算符:     setA & setB , setA.Intersection(B)\n",
    ">> 2. 并集: 逻辑运算符:     setA | setB , setA.unlon(B)=》应用：快速统计两个集合元素的个数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f2d19387",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'banana', 'orange', 'apple', 'pear'} <class 'set'>\n"
     ]
    }
   ],
   "source": [
    "basket = {'apple','orange','apple','pear','orange','banana'}\n",
    "print(basket,type(basket))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "340bfbc8",
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'set' object is not subscriptable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "Input \u001b[1;32mIn [16]\u001b[0m, in \u001b[0;36m<cell line: 1>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mbasket\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m]\u001b[49m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'set' object is not subscriptable"
     ]
    }
   ],
   "source": [
    "basket[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "b142d3ba",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id = {1800002,1800003,1800111,1800122}\n",
    "合唱团_user_id = {1800003,1800009,1800007,1800111,1801111}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "d1c8f4ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id & 合唱团_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "4af6a32c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800003, 1800111}"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.intersection(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "f372f35c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id) + len(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "fa7051c8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "7"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(舞蹈社_user_id | 合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b8ebdaad",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{1800002, 1800003, 1800007, 1800009, 1800111, 1800122, 1801111}"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "舞蹈社_user_id.union(合唱团_user_id)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8ba89407",
   "metadata": {},
   "outputs": [],
   "source": [
    "舞蹈社_user_id"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "421075b3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 思考： 如果是列表的话，想要找出重复的项？\n",
    "舞蹈社_user_id_list = [1800002,1800003,1800111,1800122]\n",
    "合唱团_user_id_list =  [1800003,1800009,1800007,1800111,1801111]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a3969b9",
   "metadata": {},
   "source": [
    "# 3. 字典（dict）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c11d6b83",
   "metadata": {},
   "source": [
    "> 1. 字典的概念和性质\n",
    ">> 1.性质：\n",
    ">>> 1. 无序性\n",
    ">>> 2. key 是惟一的（没有重复）\n",
    ">>> 3. key 是不可变的\n",
    "\n",
    "> 2. 字典的创建\n",
    ">> 1. 按照字典的形态创建字典\n",
    "\n",
    "\n",
    "\n",
    ">> 2. 使用dict()方法创建字典\n",
    "网新2班 = dict(\n",
    "     stu190001:\n",
    "     stu190002:\n",
    "     stu190003:\n",
    "\n",
    "> 3. 字典的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "cdc3e439",
   "metadata": {},
   "outputs": [],
   "source": [
    "wechat = {\n",
    "    \"fgyqeu7489fhdjk\":[\"Zhichao\",\"冰岛\",\"朋友圈\",\"男\",\"180\",\"置顶聊天\",\"会话\"],\n",
    "    \"bfdjiwg84234dfg\":[\"Jack\",\"香港\"]\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "48db5f02",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Zhichao', '冰岛', '朋友圈', '男', '180', '置顶聊天', '会话']"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "wechat[\"fgyqeu7489fhdjk\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "350599ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新1班 = {\n",
    "    1800001:\"李华\",\n",
    "    1800002:\"小明\",\n",
    "    1800003:\"Jack\",\n",
    "    1800004:\"Marry\"\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "01286ae9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1800001: '李华', 1800002: '小明', 1800003: 'Jack', 1800004: 'Marry'} <class 'dict'>\n"
     ]
    }
   ],
   "source": [
    "print(网新1班,type(网新1班))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "9dbfc30a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小明'"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新1班[1800002]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b48e1532",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新2班 = dict(\n",
    "    stu190001=\"小红\",\n",
    "    stu190002=\"小李\",\n",
    "    stu190003=\"小张\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "dc7fa838",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小红'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新2班[\"stu190001\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4a0f2667",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
